<template>
  <div class="msite-header">
    <div class="district" @click="showDisSelect()">
      <div class="district-select">
        <span><i class="iconfont">&#xe695;</i>{{district}}</span>
      </div>
      <div class="district-weather">
        <div>
          <h2>{{weatherList.temperature}}°</h2>
          <p>{{weatherList.description}}</p>
        </div>
        <img :src="'//fuss10.elemecdn.com/' + weatherList.image_hash +'.png?imageMogr/format/webp/thumbnail/!69x69r/gravity/Center/crop/69x69/'" alt="">
      </div>
    </div>
    <router-link to="/search/#" class="search-btn"><input type="text" placeholder="搜索商家、商品"></router-link>
    <div class="hot-key">
      <ul>
        <li @click="setWord(item.word)" :key="index" v-for="(item,index) in searchList">{{item.word}}</li>
      </ul>
      <!-- <router-link @click="setWord(item.word)" :to="'/search/searchList?keyWord='+item.word" :key="index" v-for="(item,index) in searchList" >{{item.word}}</router-link> -->
    </div>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
  name: 'msiteheader',
  computed: {
    ...mapState(['searchList', 'weatherList', 'district'])
  },
  methods: {
    ...mapMutations({
      search: 'SEARCH',
      weather: 'WEATHER',
      showDisSelect: 'SHOWDISSELECT',
      srhTxt: 'SEARCHTXT'
    }),
    setWord (txt) {
      console.log(1)
      var have = localStorage.getItem('searchWord')
      var haveJson = JSON.parse(have)
      if (!have) {
        var arr = []
        arr.push(txt)
        localStorage.setItem('searchWord', JSON.stringify(arr))
      }
      if (have) {
        if (haveJson.indexOf(txt) === -1) {
          var haveto = JSON.parse(have)
          haveto.unshift(txt)
          localStorage.setItem('searchWord', JSON.stringify(haveto))
        } else {
          var arr1 = haveJson.filter(function (value) {
            return value !== txt
          })
          arr1.unshift(txt)
          localStorage.removeItem('searchWord')
          localStorage.setItem('searchWord', JSON.stringify(arr1))
        }
        console.log(2)
      }
      this.srhTxt(txt)
      console.log(3)
      location.href = 'http://localhost:8080/#/search/searchList?keyWord=' + txt
    }
  },
  mounted () {
    this.search()
    this.weather()
  }
}
</script>

<style lang="scss" scoped>
@import '../../static/hotcss/px2rem.scss';
.msite-header {
  width: 100%;
  padding: px2rem(20) px2rem(28);
  background-image: linear-gradient(90deg,#0af,#0085ff);
  .district {
    height: px2rem(69);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    .district-select {
      max-width: 60%;
      span {
        font-size: px2rem(36);
        margin-right: px2rem(10);
        display: inline-block;
        width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        i {
          font-size: px2rem(34);
          margin-right: px2rem(10);
        }
      }
    }
    .district-weather {
      display: flex;
      h2 {
        font-size: px2rem(26);
        line-height: px2rem(26);
        font-weight: normal;
        text-align: right;
      }
      p {
        font-size: px2rem(24);
      }
      img {
        display: block;
        width: px2rem(55);
        height: px2rem(55);
        margin-left: px2rem(10);
      }
    }
  }
  .search-btn {
    input {
      display: block;
      width: 100%;
      height: px2rem(72);
      margin: px2rem(15) 0;
      border:none;
      outline: none;
      border-radius: px2rem(36);
      text-align: center;
      line-height: px2rem(72);
      font-size: px2rem(26);
      color: #333;
      box-shadow: 0 0.026667rem 0.066667rem 0 rgba(0,0,0,.2);
    }
  }
  .hot-key {
    width: 100%;
    white-space: nowrap;
    overflow: auto;
    line-height: px2rem(24);
    ul{
      display: flex;
      li{
        // float: left;
        font-size: px2rem(24);
        margin-right: px2rem(20);
        text-decoration: none;
        color: #fff;
        line-height: px2rem(24);
      }
    }
    // a {
    //   font-size: px2rem(24);
    //   margin-right: px2rem(20);
    //   text-decoration: none;
    //   color: #fff;
    //   line-height: px2rem(24);
    // }
  }
}
</style>


